package com.health.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import com.health.MainActivity_Menu_Tj;
import com.health.NovaApplication;
import com.health.R;
import com.health.ShowJieLunPicActivity;
import com.health.tablebean.ARCHIVE_BASEINFO;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 健康管理Adapter
 * 
 * @author nova
 *
 */
public class DocHealthAdapter extends BaseAdapter {

	private List<ARCHIVE_BASEINFO> infoList;
	private Context context;

	public DocHealthAdapter(Context context, List<ARCHIVE_BASEINFO> infoList) {
		super();
		this.context = context;
		this.infoList = infoList;
	}

	public void setInfoList(List<ARCHIVE_BASEINFO> infoList) {
		this.infoList = infoList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.dochealthmanage_list_item, null);
			holder = new ViewHolder();
			holder.nameTv = (TextView) convertView.findViewById(R.id.tongji_list_name);
			holder.sexTv = (TextView) convertView.findViewById(R.id.tongji_list_sex);
			holder.phoneTv = (TextView) convertView.findViewById(R.id.tongji_list_phone);
			holder.idCardTv = (TextView) convertView.findViewById(R.id.tongji_list_idcard);
			holder.ysjyTv = (TextView) convertView.findViewById(R.id.tongji_list_ysjy);
			holder.zhtjsjTv = (TextView) convertView.findViewById(R.id.tongji_list_zhtjsj);
			holder.isUpdataTv = (TextView) convertView.findViewById(R.id.tongji_list_isupdatadate);
			holder.examDataTv = (ImageView) convertView.findViewById(R.id.tongji_list_examdate);
			holder.jdrqTv = (TextView) convertView.findViewById(R.id.tongji_list_jdrq);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

	   final ARCHIVE_BASEINFO info = infoList.get(position);
		holder.nameTv.setText(info.getCUSTOMERNAME());
		holder.sexTv.setText(info.getSEX().equals("DM01-08_1") ? "男" : "女");
		holder.phoneTv.setText(info.getPHONE());
		holder.idCardTv.setText(info.getIDCARD());
		holder.ysjyTv.setText("体检建议：1.少吃肉，根据人体的PH来看，人的血液和细胞内都是成弱碱性，而肉类会破坏酸碱平衡，容易诱发疾病。");
		holder.zhtjsjTv.setText(fromDate2Str(info.getLAST_UPDATE_DATE()));
//		holder.examDataTv.setText("体检数据");
//		holder.examDataTv.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
		
		holder.jdrqTv.setText(fromDate2Str(info.getCREATED_DATE()));
		String isupdate=info.getIS_UPDATE();
		holder.isUpdataTv.setText("否");//默认是未上传
		if(isupdate.equals("Y")){
			//Y未上传
			holder.isUpdataTv.setText("否");
		}else if(isupdate.equals("N")){
			holder.isUpdataTv.setText("是");
		}
		
		
		if (position % 2 == 0) {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
		} else {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.table_row_odd));
		}

		//体检数据
		holder.examDataTv.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(context, ShowJieLunPicActivity.class);
				NovaApplication.setUserInfo(info);
				context.startActivity(intent);
			}
		});
		return convertView;
	}

	private String fromDate2Str(Date date) {
		if (date == null) {
			return "";
		}
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
		return format.format(date);
	}

	private class ViewHolder {

		TextView nameTv;// 姓名
		TextView sexTv;// 性别
		TextView idCardTv;// 身份证号
		TextView phoneTv;// 联系电话
		TextView zhtjsjTv;// 最后体检时间
		ImageView examDataTv;// 查看体检数据
		TextView ysjyTv;// 医生建议
		TextView isUpdataTv;// 是否上传
		TextView jdrqTv;// 是否上传
	}

}
